package com.fcscs.cservice.ws.endpoint;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

import com.fcscs.cservice.ws.schema.urlservice.GetUrlRequest;
import com.fcscs.cservice.ws.schema.urlservice.GetUrlResponse;
import com.fcscs.ecms.service.ECMSUrlManager;

/**
 * @author pvttinh
 * 
 */

@Endpoint
public class UrlServiceEndpoint {

	@Autowired
	private ECMSUrlManager urlMgr;
	
	/**
	 * 
	 * @param req
	 * @return
	 */
	@PayloadRoot(localPart = CServiceWSConstants.GET_URL_RQ, namespace = CServiceWSConstants.URL_SERVICE_NAMESPACE_URI)
	@ResponsePayload
	public GetUrlResponse getUrl(@RequestPayload GetUrlRequest req) {

		GetUrlResponse resp = new GetUrlResponse();
		try{
			resp.setUrlInfo(this.urlMgr.getUrlInfo(req.getModuleId(), req.getOrgId(), req.getPropId()));
			resp.setSuccess(true);
		}catch (Exception e) {
			// TODO: handle exception
			resp.setSuccess(false);
			resp.setErrorMessage(e.getMessage());
		}
		
		return resp;
	}
}
